<?php
/**
 * Copyright (c) 2018-2019.
 *  This file is part of the moonpie production
 *  (c) johnzhang <875010341@qq.com>
 *  This source file is subject to the MIT license that is bundled
 *  with this source code in the file LICENSE.
 */

use think\migration\db\Column;
use think\migration\Migrator;

/**
 * 这里需要处理的是，为公众号的用户提供标签关系记录
 */
class AlterUserSystem extends Migrator
{
    protected $tableMain = 'wechat_account_user_tags';
    /**
     * 执行数据
     */
    public function up()
    {
        if(!$this->hasTable($this->tableMain)){
            $table = $this->table($this->tableMain, ['engine' => 'InnoDB', 'comment' => '确定公众号用户标签的表']);
            $table
                ->addColumn(Column::integer('wxuser_id')->setComment('微信用户ID'))
                ->addColumn(Column::smallInteger('tag_id')->setComment('微信标签ID'))
                ->addColumn(Column::integer('create_at')->setComment('记录添加时间'))
                ->addColumn(Column::integer('update_at')->setComment('记录修改时间'))
                ->addIndex(['wxuser_id', 'tag_id'], ['name' => 'unique_user_tag', 'unique' => true])
                ->create();
        }
    }
    /**
     * 回滚处理
     */
    public function down()
    {
        if($this->hasTable($this->tableMain)){
            $this->dropTable($this->tableMain);
        }
    }
}
